package com.dblibrary;

import java.util.ArrayList;

import com.dblibrary.DoListOpenHelper.DoListColumns;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.os.Bundle;
import android.util.Log;

public class TodayDao extends DaoClass {

	final static String DAY_NAME ="today";
	private Bundle tmpBundle;
	private ArrayList<Bundle> contentList; 
	
	protected TodayDao(Context con) {
		super(con);
	}


	@Override
	public boolean moveTo() {
		return false;
	}

	@Override
	public boolean deleteAll() {
		return false;
	}

	@Override
	public ArrayList<Bundle> select() {
		return null;
	}

	@Override
	public ArrayList<Bundle> selectAll(int mHurryModeFlag) {
		if(contentList!=null){
			contentList.clear();
		}
		contentList = new ArrayList<Bundle>();
		DoListOpenHelper dbOpen = new DoListOpenHelper(mContext);
		SQLiteDatabase db = dbOpen.getReadableDatabase();
		SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
		builder.setTables(DoListColumns.TABLE_NAME);
		Cursor mCursor = builder.query(db, null, "importance=" + mHurryModeFlag
				+ " AND day = "+"'"+ DAY_NAME+"'", null, null, null, null);
		mCursor.moveToFirst();
		for (int i = 0; i< mCursor.getCount();i++){
			tmpBundle = new Bundle();
			tmpBundle.putInt("_id", mCursor.getInt(0));
			tmpBundle.putString("content", mCursor.getString(1));
			tmpBundle.putInt("importance", mCursor.getInt(2));
			tmpBundle.putString("day", mCursor.getString(3));
			contentList.add(tmpBundle);
			mCursor.moveToNext();
		}
		mCursor.close();
		db.close();
		dbOpen.close();
		return contentList;
	}

	@Override
	public boolean insert(String inputString, int colorFlag) {
		DoListOpenHelper db= new DoListOpenHelper(mContext);
		ContentValues values = new ContentValues();
		values.put(DoListColumns.CN_CONTENT, inputString);
		values.put(DoListColumns.CN_DAY, DAY_NAME);
		values.put(DoListColumns.CN_IMPORTANCE, colorFlag);
		db.getWritableDatabase().insert(DoListColumns.TABLE_NAME,null, values);
		db.close();
		return true;
	}


	@Override
	public boolean modify() {
		// TODO Auto-generated method stub
		return false;
	}

}
